package com.mzj.saas.mservice.my.controller;

import com.mzj.saas.commons.ApiData;
import com.mzj.saas.commons.ResultBean;
import com.mzj.saas.mservice.my.service.MyService;
import com.mzj.saas.mservice.my.vo.*;
import com.mzj.saas.mservice.wallet.vo.WalletDetailVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 我的接口
 */
@Controller
@RequestMapping("/my")
public class MyController {
	@Autowired
	private MyService myService;

	/**
	 * 我的信息
	 *
	 * @param accessToken
	 * @return
	 */
	@GetMapping("/findMyInfo")
	@ResponseBody
	public ResultBean<MyInfoVO> findMyInfo(@RequestHeader String accessToken) {
		return myService.findMyInfo(accessToken);
	}

	/**
	 * 上传身份证照片
	 *
	 * @param accessToken
	 * @param type
	 *            身份证类型：1正面 2背面
	 * @param file
	 * @return
	 */
	@PostMapping("/uploadIdCard")
	@ResponseBody
	public ResultBean<Object> uploadIdCard(@RequestHeader String accessToken,
			// @RequestParam(value = "cardNumber") String cardNumber,
			@RequestParam(value = "type") Integer type, @RequestParam(value = "file") MultipartFile file) {
		return myService.uploadIdCard(accessToken, type, file);
	}

	/**
	 * 实名认证
	 *
	 * @param accessToken
	 * @return
	 */
	@PostMapping("/certification")
	@ResponseBody
	public ResultBean<Object> certification(@RequestHeader String accessToken, @RequestBody CertificationVO vo) {
		return myService.certification(accessToken, vo);
	}

	/**
	 * 房屋绑定
	 *
	 * @param accessToken
	 * @param phone
	 * @param cardNumber
	 * @return
	 */
	@GetMapping("/houseBind")
	@ResponseBody
	public ResultBean<Object> houseBind(@RequestHeader String accessToken,
			@RequestParam(value = "phone", required = false) String phone,
			@RequestParam(value = "code", required = false) String code,
			@RequestParam(value = "cardNumber", required = false) String cardNumber) {
		return myService.houseBind(accessToken, phone, code, cardNumber);
	}

	/**
	 * 查看实名认证
	 *
	 * @param accessToken
	 * @return
	 */
	@GetMapping("/findCertification")
	@ResponseBody
	public ResultBean<CertificationVO> findCertification(@RequestHeader String accessToken) {
		return myService.findCertification(accessToken);
	}

	/**
	 * 查看我的房屋
	 *
	 * @param accessToken
	 * @param pageNumber
	 * @param pageSize
	 * @return
	 */
	@GetMapping("/findMyHouse")
	@ResponseBody
	public ResultBean<ApiData<MyHouseVO>> findMyHouse(@RequestHeader String accessToken,
			@RequestParam(defaultValue = "0") Integer pageNumber, @RequestParam(defaultValue = "5") Integer pageSize) {
		return myService.findMyHouse(accessToken, pageNumber, pageSize);
	}

	/**
	 * 提现
	 *
	 * @param accessToken
	 * @return
	 */
	@PostMapping("/withdrawal")
	@ResponseBody
	public ResultBean<Object> accountWithdrawal(@RequestHeader String accessToken,
			@RequestBody AccountWithdrawalVO vo) {
		return myService.accountWithdrawal(accessToken, vo);
	}

	/**
	 * 钱包明细与提现列表
	 *
	 * @param accessToken
	 * @param pageNumber
	 * @param pageSize
	 * @return
	 * @author shun
	 * @date 2021年6月23日
	 */
	@GetMapping("/wallet")
	@ResponseBody
	public ResultBean<WalletDetailVO> withdrawList(@RequestHeader String accessToken,
			@RequestParam(defaultValue = "0") Integer pageNumber, @RequestParam(defaultValue = "5") Integer pageSize) {
		return myService.withdrawList(accessToken, pageNumber, pageSize);
	}

	/**
	 * 账户切换
	 *
	 * @param accessToken
	 * @param type
	 * @return
	 * @author shun
	 * @date 2021年6月24日
	 */
	@PostMapping("/account/switch/{type}")
	@ResponseBody
	public ResultBean<Object> accountSwitch(@RequestHeader String accessToken, @PathVariable Integer type) {
		return myService.accountSwitch(accessToken, type);
	}

	/**
	 * 手机号码验证
	 *
	 * @param accessToken
	 * @param phone
	 * @param password
	 * @return
	 * @author shun
	 * @date 2021年6月28日
	 */
	@PostMapping("/phone/validate/{phone}/{password}")
	@ResponseBody
	public ResultBean<Object> validatePhone(@RequestHeader String accessToken, @PathVariable String phone,
			@PathVariable String password) {
		return myService.validatePhone(accessToken, phone, password);
	}

	/**
	 * 用户更换手机号码
	 *
	 * @param accessToken
	 * @param phone
	 * @param code
	 * @return
	 * @author shun
	 * @date 2021年6月28日
	 */
	@PostMapping("/phone/{phone}/{code}")
	@ResponseBody
	public ResultBean<Object> updatePhone(@RequestHeader String accessToken, @PathVariable String phone,
			@PathVariable String code) {
		return myService.updatePhone(accessToken, phone, code);
	}

	/**
	 * 解绑房屋
	 *
	 * @param accessToken
	 * @param vo
	 * @return
	 */
	@PostMapping("/houseUnbind")
	@ResponseBody
	public ResultBean<Object> houseUnbind(@RequestHeader String accessToken, @RequestBody HouseUnbindVO vo) {
		return myService.houseUnbind(accessToken, vo);
	}

	/**
	 * 注销
	 *
	 * @return
	 */
	@RequestMapping(path = "/logout", method = RequestMethod.PUT)
	@ResponseBody
	public ResultBean<Object> logout(@RequestHeader String accessToken) {
		return myService.logout(accessToken);
	}

}
